//窗口初始化
$(document).ready(function() {
    $('#Window_table').DataTable( {
        // fixedHeader: true
    } );
} );
$(document).ready(function() {
    $('#BasicMessage_table').DataTable( {
        // fixedHeader: true
    } );
} );
//判断数组中是否存在某个字符串
function inArray(arr,item) {
    for(let i=0;i<arr.length;i++){
        if(arr[i] == item){
            return true;
        }
    }
    return false;
};

//窗口内垃圾短信展示
function Window_show() {
    let optionJson = [];
    //给后台传参
    let request_parameters = {type:"get_spam_message_data"};
    if(flag == 1){
        $("#waste_win").modal("show")
        $.ajax({
            type:"post",
            url:"http://127.0.0.1:9998/preprocessed/get_spam_message_data/200",
            data:request_parameters,
            async: false,
            success:function (call_record_complete_info) {
                console.log(call_record_complete_info);
                optionJson=call_record_complete_info;
                $("#Window_table").dataTable().fnDestroy();//还原初始化
                $('#Window_table').DataTable({
                    // "serverSide":true,
                    //  "paging":true,
                    // "lengthMenu":[15,25,35,100,25],
                    // "pagingType":"scrolling",
                    // serverSide:true,
                    // Processing:true,
                    // deferRender:true,
                    bStateSave:true,//翻页时保存状态
                    // iDisplayLength:10,
                    // iDisplayStart:0,
                    ordering:false,//禁用全局排序
                    data:optionJson.data,
                    //设置列数据
                    columns:[
                        {"data": 'sendNum'},
                        {"data": 'recNum'},
                        {"data": 'time'},
                        {"data": 'content'},
                        {"data": 'userLocation'},
                    ],
                    //设置排序
                    "order":[[1,'asc']],
                    //设置语言
                    language: {
                        "sProcessing": "处理中...",
                        "sLengthMenu": "显示 _MENU_ 项搜索结果",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 条数据",
                        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "未搜索到数据",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    },
                });
            }
        });
    }
    else{
        alert("请先导入短信记录表");
    }
}
//定义全局变量optionJson
let optionJson = [];
let flag =0;
//短信数据导入
function MessageExport() {
    flag = 1;
    //给后台传参
    let request_parameters = {type:"completing_message_data"};
    $.ajax({
        type:"post",
        url:"http://127.0.0.1:9998/preprocessed/completing_message_data",
        async: false,
        data:request_parameters,
        success:function (call_record_complete_info) {
              console.log(call_record_complete_info);
            optionJson=call_record_complete_info;
            $("#BasicMessage_table").dataTable().fnDestroy();//还原初始化
            $('#BasicMessage_table').DataTable({
                // "serverSide":true,
                //  "paging":true,
                // "lengthMenu":[15,25,35,100,25],
                // "pagingType":"scrolling",
                // serverSide:true,
                // Processing:true,
                // deferRender:true,
                bStateSave:true,//翻页时保存状态
                // iDisplayLength:10,
                // iDisplayStart:0,
                ordering:false,//禁用全局排序
                data:optionJson.data,
                //设置列数据
                columns:[
                    {"data": 'sendNum',
                        "render":function (data,type,row,meta) {//判断该字段是否在completing_fields中，若在的话，设为空
                            if(inArray(row.completing_fields,"sendNum")){
                                return data = null;
                            }
                            else{
                                return data = '<p style="text-align: center">'+data+'</p>'
                            }
                        }
                    },
                    {"data": 'recNum',
                        "render":function (data,type,row,meta) {//判断该字段是否在completing_fields中，若在的话，设为空
                            if(inArray(row.completing_fields,"recNum")){
                                return data = null;
                            }
                            else{
                                return data = '<p style="text-align: center">'+data+'</p>'
                            }
                        }
                        },
                    {"data": 'time',
                        "render":function (data,type,row,meta) {//判断该字段是否在completing_fields中，若在的话，设为空
                            if(inArray(row.completing_fields,"time")){
                                return data = null;
                            }
                            else{
                                return data = '<p style="text-align: center">'+data+'</p>'
                            }
                        }
                    },
                    {"data": 'content',
                        "render":function (data,type,row,meta) {//判断该字段是否在completing_fields中，若在的话，设为空
                            if(inArray(row.completing_fields,"content")){
                                return data = null;
                            }
                            else{

                                return data;
                            }
                        }
                    },
                    {"data": 'userLocation',
                        "render":function (data,type,row,meta) {//判断该字段是否在completing_fields中，若在的话，设为空
                            if(inArray(row.completing_fields,"userLocation")){
                                return data = null;
                            }
                            else{
                                   return data ='<p style="text-align: center;">'+data+'</p>';
                            }
                        }
                    },
                ],
                //设置排序
                "order":[[1,'asc']],
                //设置语言
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项搜索结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 条数据",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "未搜索到数据",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
            });
        }
    });
}

//短信数据补齐
function Add_Messagedata(){
    if(flag == 1){
        $("#BasicMessage_table").dataTable().fnDestroy();//还原初始化
        $('#BasicMessage_table').DataTable({
            // "serverSide":true,
            //  "paging":true,
            // "lengthMenu":[15,25,35,100,25],
            // "pagingType":"scrolling",
            // serverSide:true,
            // Processing:true,
            // deferRender:true,
            bStateSave:true,//翻页时保存状态
            // iDisplayLength:10,
            // iDisplayStart:0,
            ordering:false,//禁用全局排序
            data:optionJson.data,
            //设置列数据
            columns:[
                {"data": 'sendNum',
                    "render":function (data,type,row,meta) {
                        if(inArray(row.completing_fields,"sendNum")){
                            return data ='<p style="color: red;text-align: center;">'+data+'</p>';
                        }
                        else{
                            return data ='<p style="color: black;text-align: center;">'+data+'</p>';
                        }
                    }
                },
                {"data": 'recNum',
                    "render":function (data,type,row,meta) {
                        if(inArray(row.completing_fields,"recNum")){
                            return data ='<p style="color: red;text-align: center;">'+data+'</p>';
                        }
                        else{
                            return data ='<p style="color: black;text-align: center;">'+data+'</p>';
                        }
                    }
                },
                {"data": 'time',
                    "render":function (data,type,row,meta) {
                        if(inArray(row.completing_fields,"time")){
                            return data ='<p style="color: red;text-align: center;">'+data+'</p>';
                        }
                        else{
                            return data ='<p style="color: black;text-align: center;">'+data+'</p>';
                        }
                    }
                },
                {"data": 'content',
                    "render":function (data,type,row,meta) {
                        if(inArray(row.completing_fields,"content")){
                            return data ='<p style="color: red;">'+data+'</p>';
                        }
                        else{
                            return data ='<p style="color: black;">'+data+'</p>';
                        }
                    }
                },
                {"data": 'userLocation',
                    "render":function (data,type,row,meta) {
                        if(inArray(row.completing_fields,"userLocation")){
                            return data ='<p style="color: red;text-align: center;">'+data+'</p>';
                        }
                        else{
                            return data ='<p style="color: black;text-align: center;">'+data+'</p>';
                        }
                    }
                },
            ],
            //设置排序
            "order":[[1,'asc']],
            //设置语言
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项搜索结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 条数据",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "未搜索到数据",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            },
        });
    }
       else{
           alert("请先导入短信记录表");
    }

}